package com.sgb.merchant.view.adapter;

import android.view.View;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.link.entity.merchant.DynamicListEntity;
import com.sgb.merchant.BR;
import com.sgb.merchant.R;

import java.util.List;

/**
 * @author: 王彬臣
 * @date: 2021/10/14
 * @Description: 产业园区动态列表
 */
public class SelfDynamicAdapter extends BaseQuickAdapter<DynamicListEntity, BaseViewHolder> {

    ClickBtnListener clickBtnListener;

    public void setClickBtnListener(ClickBtnListener clickBtnListener) {
        this.clickBtnListener = clickBtnListener;
    }

    public SelfDynamicAdapter(@Nullable @org.jetbrains.annotations.Nullable List<DynamicListEntity> data) {
        super(R.layout.merchant_self_item_dynamic, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, DynamicListEntity item) {
        ViewDataBinding binding = DataBindingUtil.bind(helper.itemView);
        binding.setVariable(BR.viewModel, item);
        helper.setOnClickListener(R.id.tv_edit, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(clickBtnListener!=null){
                    clickBtnListener.editClick(item,helper.getLayoutPosition());
                }


            }
        });
        helper.setOnClickListener(R.id.tv_del, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(clickBtnListener!=null){
                    clickBtnListener.delClick(item.getNo(),helper.getLayoutPosition());
                }
            }
        });
    }
    public interface ClickBtnListener {

        void editClick(DynamicListEntity entity, int position);

        void delClick(String no, int position);
    }
}
